#extension GL_EXT_gpu_shader4 : enable
	varying vec4 diffuse,ambientGlobal, ambient, catface;
	varying vec3 normal,lightDir,halfVector;
	varying float dist;
	uniform sampler2D textureImage;
	
	vec4 checker3D(float x, float y, float z, vec4 color0, vec4 color1)
	{
	  if ((int(floor(x) + floor(y) + floor(z)) & 1) == 0)
		return color0;
	  else
		return color1;
	}

	void main()
	{
		vec3 n,halfV,viewV,ldir;
		float NdotL,NdotHV;
		
		float s = gl_FragCoord.x / 10.0;
		float t = gl_FragCoord.y / 10.0;
		float RAPIDITY = 5.5;
	
		vec4 c1 = vec4(0.9,0.5,0,1); // bg
		vec4 c2 = vec4(1,1,1,1);
		vec4 diffuse2 = diffuse*.5+0.5*checker3D( catface.x*RAPIDITY,catface.y*RAPIDITY,catface.z*RAPIDITY,c1,c2);
		
		vec4 color = ambientGlobal*.5;
		float att;
		
		/* a fragment shader can't write a varying variable, hence we need
		a new variable to store the normalized interpolated normal */
		n = normalize(normal);
		
		/* compute the dot product between normal and normalized lightdir */
		NdotL = max(dot(n,normalize(lightDir)),0.0);
		
		
	
		if (NdotL > 0.0) {
		
			att = 1.0 / (gl_LightSource[0].constantAttenuation +
					gl_LightSource[0].linearAttenuation * dist +
					gl_LightSource[0].quadraticAttenuation * dist * dist);
			color += att * (diffuse2 * NdotL + ambient);
		
			
			halfV = normalize(halfVector);
			NdotHV = max(dot(n,halfV),0.0);
			color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * 
							pow(NdotHV,gl_FrontMaterial.shininess);
		}

		//gl_FragColor = vec4(gl_FragCoord.x,gl_FragCoord.y,0,1);
		gl_FragColor = color;
		
		//gl_FragColor = NdotL * vec4(1,.5,0,0);
		//gl_FragColor = texture2D( textureImage, gl_TexCoord[0].st );
	}
